package g4p.newg4p;

import java.util.ArrayList;
import java.util.List;

import g4p_controls.GDropList;
import g4p_controls.GEvent;
import processing.core.PApplet;

@SuppressWarnings("serial")
public class DropListTest extends PApplet {

	GDropList d0, d1;
	String[] list = new String[12];

	public void setup(){
		size(400,400);
		d0 = new GDropList(this, 20,20,150,140,6);
		d0.tag = "### Made from ARRAY ###";
		d1 = new GDropList(this, 220,20,150,140,6);
		d1.tag = "### Made from LIST ###";

		String[] array = new String[12];
		for(int i = 0; i < array.length; i++){
			array[i] = "Option " + i;
		}
		d0.setItems(array, 0);

		List<String> list = new ArrayList<String>();
		for(int i = 0; i < array.length; i++){
			list.add("Option " + i);
		}
		d1.setItems(list, 3);
	}


	public void keyTyped(){
		System.out.println("BEFORE\t" + d0.getSelectedIndex() + "   " + d0.getSelectedText());
		int kn = key - '0';
		switch(kn){
		case 0:
			d0.removeItem(0);
			break;
		case 1:
			d0.removeItem(11);
			break;
		case 2:
			d0.removeItem(d0.getSelectedIndex());
			break;
		case 3:
			d0.insertItem(2, "Inserted at " + millis());
			break;
		case 4:
			break;
		case 5:
			d0.insertItem(d0.getSelectedIndex(), "Inserted at selected");
			break;
		case 6:
			break;
		case 7:
			break;
		case 8:
			break;
		case 9:
			break;
		}
		System.out.println("AFTER \t" + d0.getSelectedIndex() + "   " + d0.getSelectedText());
	}
	public void draw(){
		background(240,240,255);

	}

	public void handleDropListEvents(GDropList list, GEvent event) { 
		System.out.println(list.tag);
		System.out.println("   " + list.getSelectedIndex() + "\t" + list.getSelectedText());

	}
}
